import { Fragment } from '@/components/Fragment'; import { Badge, View } from '@aws-amplify/ui-react'; import { Example, ExampleCode } from '@/components/Example'; import { ComponentStyleDisplay } from '@/components/ComponentStyleDisplay'; import ThemeExample from '@/components/ThemeExample.mdx'; import { BadgeDemo } from './demo'; import { DefaultBadgeExample, BadgeVariationExample, BadgeSizeExample, BadgeStyleProps, BadgeThemeExample, } from './examples'; ## Demo ## Usage Import the Badge primitive and styles. ```jsx file=./examples/DefaultBadgeExample.tsx ``` ### Variations Use the `variation` prop to change the Badge variation. Available options are `info`, `error`, `warning`, `success`, and none (default). ```jsx file=./examples/BadgeVariationExample.tsx ``` ### Sizes Use the `size` prop to change the Badge size. Available options are `small`, `large`, and none (default). ```tsx file=./examples/BadgeSizeExample.tsx ``` ## CSS Styling ```tsx file=./examples/BadgeThemeExample.tsx ``` ### Target classes ### Global styling To override styling on all Badges, you can set the Amplify CSS variables or use the built-in `.amplify-badge` class. ```css /* styles.css */ [data-amplify-theme] { --amplify-components-badge-background-color: yellow; } /* OR */ .amplify-badge { background-color: yellow; } ``` To replace the Badge styling, unset it: ```css .amplify-badge { all: unset; /* Add your styling here*/ } ``` ### Local styling To override styling on a specific Badge, you can use (in order of increasing specificity): a class selector, data attributes, or style props. _Using a class selector:_ 13 ```css /* styles.css */ .flagged { color: white; background-color: crimson; border-radius: 3px; } ``` ```jsx import './styles.css'; 13; ``` _Using data attributes:_ ```css /* styles.css */ /* Override only info variation styles */ .amplify-badge[data-variation='info'] { background-color: rebeccapurple; } /* Override only large size styles */ .amplify-badge[data-size='large'] { border: 1px solid black; } ``` ```jsx import './styles.css'; Purple background Black border ``` _Using style props:_ ```jsx file=./examples/BadgeStyleProps.tsx ```